package com.nwpu.common;


import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 统一返回对象
 */

@Data
@AllArgsConstructor
public class Result<T> implements Serializable {
    /**
     * 通信数据
     */
    private T data;

    /**
     * 状态码
     */
    private String code = "200";

    /**
     * 通信描述
     */
    private String msg = "操作成功";

    /**
     * 通过静态方法获取实例
     */
    public static <T> Result<T> of(T data) {
        return new Result<>(data);
    }

    public static <T> Result<T> of(T data, String msg) {
        return new Result<>(data, msg);
    }

    public static <T> Result<T> error(ErrorEnum errorEnum) {
        return new Result<>(null, errorEnum.getCode(), errorEnum.getMsg());
    }

    @Deprecated
    public Result() {

    }

    private Result(T data) {
        this.data = data;
    }

    public Result(T data, String msg) {
        this.data = data;
        this.msg = msg;
    }
}